package com.example.design.status;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author: Bin.L
 * @date: 2022/3/14  10:30
 * @Description: Definition the state and action enum of test
 */
public class DefinitionEnum {

    /**
     * Task status enum
     */
    @AllArgsConstructor
    @Getter
    public enum TaskState {
        INIT("初始化"),
        ONGOING("进行中"),
        PAUSED("暂停中"),
        FINISHED("已完成"),
        EXPIRED("已过期");

        private final String message;
    }

    /**
     * Action enum （ Action Affects State Changes）
     */
    @AllArgsConstructor
    @Getter
    enum ActionType {
        START(1, "开始"),
        STOP(2, "暂停"),
        ACHIEVE(3, "完成"),
        EXPIRE(4, "过期");
        private final int code;
        private final String message;
    }

    /**
     * 模拟用IF判断来实现业务功能的伪代码
     * （状态流转的控制可以使用状态模式）
     */
    /*public void updateState(ActionType actionType) {
        if (state == TaskState.INIT) {
            if (actionType == ActionType.START) {
                state = TaskState.ONGOING;
            }
        } else if (state == TaskState.ONGOING) {
            if (actionType == ActionType.ACHIEVE) {
                state = TaskState.FINISHED;
                // 任务完成后进对外部服务进行通知 （通知可以用观察者模式）
                activityService.notifyFinished(taskId);
                taskManager.release(taskId);
            } else if (actionType == ActionType.STOP) {
                state = TaskState.PAUSED;
            } else if (actionType == ActionType.EXPIRE) {
                state = TaskState.EXPIRED;
            }
        } else if (state == TaskState.PAUSED) {
            if (actionType == ActionType.START) {
                state = TaskState.ONGOING;
            } else if (actionType == ActionType.EXPIRE) {
                state = TaskState.EXPIRED;
            }
        }
    }*/
}
